package ioc06;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Author：汤小洋
 * Date：2022-11-23 9:19
 * Description：<描述>
 */
// @Scope("prototype")
// @Lazy
@Component // 默认情况下，bean的id的为类名首字母小写，即springBean
// @Component("springBean")
public class SpringBean {

    // @Value("tom")
    @Value("${name}")
    private String name;

    @Value("${age}")
    private int age;

    @Autowired
    private OtherBean otherBean;


    @Override
    public String toString() {
        return "SpringBean{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", otherBean=" + otherBean +
                '}';
    }


    @PostConstruct
    public void init() {
        System.out.println("SpringBean.init()");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("SpringBean.destroy()");
    }
}
